package interfacesSIAB;

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.GridBagLayout;
import javax.swing.BorderFactory;
import java.awt.Color;
import javax.swing.border.TitledBorder;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import com.sun.org.apache.xml.internal.security.encryption.AgreementMethod;

import administrador.*;
public class IngresarCliente extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JPanel jPanel = null;
	private JLabel jLabel = null;
	private JLabel jLabel1 = null;
	private JLabel jLabel2 = null;
	private JLabel jLabel3 = null;
	private JLabel jLabel4 = null;
	private JTextField nombre = null;
	private JTextField cedula = null;
	private JTextField apellido = null;
	private JTextField telefono = null;
	private JTextField direccion = null;
	private JButton guardar = null;
	private JLabel email = null;
	private JTextField email1 = null;
	private JButton Salir = null;

	/**
	 * This is the default constructor
	 */
	public IngresarCliente() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(343, 430);
		this.setResizable(false);
		this.setContentPane(getJContentPane());
		this.setTitle("Registrar Cliente");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJPanel(), null);
			jContentPane.add(getGuardar(), null);
			jContentPane.add(getSalir(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			email = new JLabel();
			email.setBounds(new Rectangle(36, 215, 60, 16));
			email.setText("  Email");
			jLabel4 = new JLabel();
			jLabel4.setBounds(new Rectangle(34, 179, 69, 16));
			jLabel4.setText("  Direccion");
			jLabel3 = new JLabel();
			jLabel3.setBounds(new Rectangle(36, 141, 65, 21));
			jLabel3.setText("  Telefono");
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(37, 46, 72, 16));
			jLabel2.setText("  Nombre(s)");
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(35, 111, 64, 16));
			jLabel1.setText("  Cedula");
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(35, 80, 66, 16));
			jLabel.setText("  Apellidos");
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBounds(new Rectangle(10, 28, 300, 273));
			jPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.orange), "Cliente", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
			jPanel.add(jLabel, null);
			jPanel.add(jLabel1, null);
			jPanel.add(jLabel2, null);
			jPanel.add(jLabel3, null);
			jPanel.add(jLabel4, null);
			jPanel.add(getNombre(), null);
			jPanel.add(getCedula(), null);
			jPanel.add(getApellido(), null);
			jPanel.add(getTelefono(), null);
			jPanel.add(getDireccion(), null);
			jPanel.add(email, null);
			jPanel.add(getEmail1(), null);
		}
		return jPanel;
	}

	/**
	 * This method initializes nombre	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getNombre() {
		if (nombre == null) {
			nombre = new JTextField();
			nombre.setBounds(new Rectangle(154, 43, 129, 20));
		}
		return nombre;
	}

	
	private JTextField getCedula() {
		if (cedula == null) {
			cedula = new JTextField();
			cedula.setBounds(new Rectangle(155, 108, 128, 20));
		}
		return cedula;
	}

	
	private JTextField getApellido() {
		if (apellido == null) {
			apellido = new JTextField();
			apellido.setBounds(new Rectangle(154, 77, 129, 20));
		}
		return apellido;
	}

	
	private JTextField getTelefono() {
		if (telefono == null) {
			telefono = new JTextField();
			telefono.setBounds(new Rectangle(156, 138, 128, 20));
		}
		return telefono;
	}

	
	private JTextField getDireccion() {
		if (direccion == null) {
			direccion = new JTextField();
			direccion.setBounds(new Rectangle(155, 175, 128, 20));
		}
		return direccion;
	}

	/**
	 * This method initializes guardar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getGuardar() {
		if (guardar == null) {
			guardar = new JButton();
			guardar.setText("Guardar");
			guardar.setBounds(new Rectangle(45, 330, 84, 25));
			guardar.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					try {
						
					 
					
					
					if(getNombre().getText().trim().length() > 0 )
					{
						if(getApellido().getText().trim().length() > 0)
						{
							
							if(getCedula().getText().trim().length() > 0)
							
							{
																
								gestion_de_clientes agregar= new gestion_de_clientes();
								agregar.agregarCliente(getNombre().getText(),getApellido().getText(),Integer.parseInt(getCedula().getText()),Integer.parseInt(getTelefono().getText()),getDireccion().getText(),getEmail1().getText());
								getNombre().setRequestFocusEnabled(true);
								getNombre().setText(" ");
								getApellido().setText("");
								getCedula().setText("");
								getTelefono().setText("");
								getDireccion().setText("");
								getEmail1().setText("");
								
							}
							else{
								JOptionPane.showMessageDialog(null,"Por favor Debe de Ingresar la Cedula");
							}
							
							
						}
						else{
							JOptionPane.showMessageDialog(null,"Por favor Debe de Ingresar el Apellido");
						}
						
						
						
						
						
					}
					else{
						
						JOptionPane.showMessageDialog(null,"Por favor Debe de Ingresar el Nombre");
					}
					
					
					}
					catch (Exception e1) {
						JOptionPane.showMessageDialog(null,"El siguiente campo no puede contener caracteres"+ e1.getMessage() );
					    e1.printStackTrace();
					}
				}
			});
		}
		return guardar;
	}

	/**
	 * This method initializes email1	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getEmail1() {
		if (email1 == null) {
			email1 = new JTextField();
			email1.setBounds(new Rectangle(157, 214, 125, 20));
		}
		return email1;
	}

	/**
	 * This method initializes Salir	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getSalir() {
		if (Salir == null) {
			Salir = new JButton();
			Salir.setBounds(new Rectangle(177, 332, 98, 23));
			Salir.setText("Salir");
			
			
Salir.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					
					dispose();
				}
			});
			
		
			
			
			
			
		}
		return Salir;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
